#ifndef CODEEXERCISE_H_
#define CODEEXERCISE_H_
#define PREFIX "./Tests/"
#include <string>
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include "Operation.h"
using namespace std;

/**
Exercise类
接受询问参数，打开文件进行读写，操作所有的Operation对象
他持有一个map对象，对应买一种股票name和Operation的数组
每次得到新数据时，它调用相应股票的Operation数组中的对象进行更新数据

**/

class Exercise{
public:
    Exercise(std::string input_filename, std::string output_filename, vector<string> query, string format);
    virtual ~Exercise(){
        this->input_stream.close();
        this->output_stream.close();
    }

    int next_line(std::string & str);
    vector<string> separate_string(const std::string &s, char separator);

    void run();

    void build_operations(vector<Operation> & vec);

    void write_to_file();

private:
    string str_format;
    vector<string> vec_format;
    std::map<string,int64_t> base_data;
    std::string input_filename;
    std::string output_filename;
    std::ifstream input_stream;
    std::ofstream output_stream;
    char separator = ',';
    map<string, vector<Operation>> op_map;
    vector<string> query;
    vector<int> query_mark;
};

#endif

